package com.refusea.train.domain.helper

import com.refusea.train.config.mvc.WebSession
import com.refusea.train.domain.entity.Classroom
import com.refusea.train.domain.ex.BizEx
import com.refusea.train.mapper.ClassroomMapper
import org.springframework.stereotype.Component

/**
 * @author Zhang Yan 2024/4/1
 **/
@Component
class ClassroomHelper(private val classroomMapper: ClassroomMapper) {

    fun list(): List<Classroom> {
        return classroomMapper.list(WebSession.user().schoolId)
    }

    fun save(req: Classroom): Int {
        req.schoolId = WebSession.user().schoolId
        if (req.id == 0) {
            classroomMapper.insert(req)
        } else {
            classroomMapper.update(req)
        }

        return req.id
    }

    fun delete(id: Int) {
        if (classroomMapper.delete(id, WebSession.user().schoolId) == 0) {
            throw BizEx.of("参数异常，请重新登录")
        }
    }

}
